// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
    },

    init (startPos, endPos, lineW = 6) {
        this.node.position = startPos;
        // 结束点到开始点的向量
        let p = endPos.sub(startPos);
        // 两点的距离
        let len = p.mag();
        // 向量相对于(0,1)的旋转角度
        let pn = p.normalizeSelf();
        let origin = cc.v2(0,1);
        let r = origin.signAngle(pn);
        let angle = cc.misc.radiansToDegrees(r);
        this.node.angle = angle - 180;

        this.node.height = len;
        this.node.width = lineW;
        // let scaleY = len / (this.node.height * this.node.scaleY);
        // this.node.scaleY = scaleY;
    }

    // update (dt) {},
});
